# -*- coding:utf8 -*-

import matplotlib.pyplot as plt
import mpld3
from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def index():
    # 创建matplotlib图形
    fig, ax = plt.subplots()
    x = [1, 2, 3, 4, 5]
    y = [1, 4, 9, 16, 25]
    ax.plot(x, y)

    # 将matplotlib图形转换为D3.js图形
    fig_html = mpld3.fig_to_html(fig)

    return render_template('index.html', fig_html=fig_html)


if __name__ == '__main__':
    app.run(debug=True)
